<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>找回密码</title>
		<script src="js/mui.min.js"></script>
		<link href="css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="css/iconfont.css" />
		<link rel="stylesheet" href="css/style.css" />
		<link rel="stylesheet" href="css/member.css" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">找回密码</h1>
		</header>
		<div class="mui-content login_con">
			<div class="login_top"><img src="images/55.png"></div>
			<form id='login-form' class="login_formbox">
				<div class="mui-input-row">
					<label><span class="iconfont icon-weibiaoti1"></span></label>
					<input id='mobile' type="text" class="mui-input-clear mui-input" placeholder="请输入电话号码">
				</div>
				<div class="mui-input-row fl_yanzm">
					<div class="left clearfix">
						<label><span class="iconfont icon-shimingrenzheng2"></span></label>
						<input id='yzm' type="text" class="mui-input-clear mui-input" placeholder="请输入验证码">
					</div>
					<a href="javascript:;" id="send_code">获取验证码</a>
				</div>
				<div class="mui-input-row">
					<label><span class="iconfont icon-mima"></span></label>
					<input id='pwd' type="password" class="mui-input-clear mui-input" placeholder="请输入密码">
				</div>
			</form>
			<div class="link_area">
				<a id='return' href="javascript:;">返回登录</a>
			</div>
			<div class="mui-content-padded getpwd_btn">
				<button class="mui-btn mui-btn-block login_btn" id="btn">确 认</button>
			</div>
		</div>
	</body>

</html>

<script type="text/javascript" src="js/castapp.js"></script>
<script type="text/javascript" src="js/app.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/layer/layer.min.js"></script>
<script type="text/javascript">
	ca.init();
	var btn = $('#btn');
	var send_code = $('#send_code');
	//true就是可以发送
	var onoff = true;
	//发送验证码
	send_code.click(function() {
		//false就不能发送
		if(!onoff) {
			return;
		}
		onoff = false;
		//点击玩按钮干什么?
		//发验证码? 
		// 1-给谁发? 手机号码
		var phone = $("#mobile").val();
		
		if(phone == '') {
			layer.msg('手机号码不能为空');
			onoff = true;
			return;
		}
		var reg = /^1[3|4|5|7|8][0-9]{9}$/; //验证规则
		if(!reg.test(phone)) {
			layer.msg('手机号码格式不正确');
			onoff = true;
			return;
		}
$.ajax({
			//请求的url
			//注意，如果我们使用路由器的情况下，我们需要设置一下本地服务器的ip地址
			url: APP.api_url + 'User/sendSMS',
			//请求的过程中传递过去的参数 json
			data: {
				mobile: phone,
				title:'找回密码'
			},
			dataType:'jsonp',
			//成功了的回调，并且带有返回值
			success: function(data) {
			layer.msg(data.msg);
						var num = 60;
						var timer = setInterval(function() {
							num--;
							if(num == 0) {
								send_code.innerHTML = '发送验证码';
								//定时器停了
								clearInterval(timer);
								onoff = true;
								send_code.html(num + 'S');
							} else {
								send_code.html(num + 'S');
							}
						}, 1000); // 1000 毫秒==1秒
			}
		})
	});
	//返回登录页
	$('#return').click(function() {
		window.location.href="login.html";
		}
	);
	//找回密码
	btn.click(function() {
		var phone = $("#mobile").val();
		var input_code = $("#yzm").val();
		var pwd = $("#pwd").val();
		var fromuid=getUrlParam('fromuid');
		if(phone == '') {
			layer.msg('手机号码不能为空');
			return;
		}
		var reg = /^1[3|4|5|7|8][0-9]{9}$/; //验证规则
		if(!reg.test(phone)) {
			layer.msg('手机号码格式不正确');
			onoff = true;
			return;
		}
		if(input_code.trim() == '') {
			layer.msg('验证码不能为空');
			return;
		}
		if(pwd.trim() == '') {
			layer.msg('密码不能为空');
			return;
		}
		btn.disabled = true;
		setTimeout(function() {
			btn.disabled = false;
		}, 1500);
		//写入数据库
		$.ajax({
			//请求的url
			//注意，如果我们使用路由器的情况下，我们需要设置一下本地服务器的ip地址
			url: APP.api_url + 'User/lose',
			dataType:'jsonp',
			//请求的过程中传递过去的参数 json
			data: {
				mobile: phone,
				verifycode: input_code,
				pwd: pwd
			},
			//成功了的回调，并且带有返回值
			success: function(data) {
			if(data.code==200){
				layer.msg(data.msg, {icon: 1,time:1500,shade: 0.1}, function(index){
                    window.location.href="login.html";
                });

			}else{
				layer.msg('更新失败');
			}
				
			},
			
		})
	});
</script>